package com.yxh.adapter;

import java.util.List;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.yxh.R;
import com.yxh.dto.BaseDto;
import com.yxh.dto.CityDto;

public class AboutMeSelectCityAdapter extends BaseAdapter {

	private List<CityDto> list;
	private LayoutInflater inflater;

	public AboutMeSelectCityAdapter(Context context, List<CityDto> list) {
		this.list = list;
		inflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public BaseDto getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@SuppressLint("InflateParams")
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		CityDto cDto = list.get(position);
		if (convertView == null) {
			convertView = inflater.inflate(
					R.layout.activity_usercenter_update_info_item, null);
			holder = new ViewHolder();
			holder.nameTv = (TextView) convertView
					.findViewById(R.id.city_layout_tv1);
			holder.selectedTv = (TextView) convertView
					.findViewById(R.id.city_layout_tv2);
			holder.hasMoreImg = (ImageView) convertView
					.findViewById(R.id.city_layout_icon);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		holder.nameTv.setText(cDto.region_name);

		if ("1".equals(cDto.flag)) {
			holder.selectedTv.setVisibility(View.VISIBLE);
		} else {
			holder.selectedTv.setVisibility(View.INVISIBLE);
		}

		if ("1".equals(cDto.hasMore)) {
			holder.hasMoreImg.setVisibility(View.VISIBLE);
		} else {
			holder.hasMoreImg.setVisibility(View.GONE);
		}

		return convertView;
	}

	static class ViewHolder {
		TextView nameTv;
		TextView selectedTv;
		ImageView hasMoreImg;

	}

}
